﻿Imports DTO
Imports System.Data.SqlClient
Public Class CQuyenTheoBoPhanDAO
    Public Function LoadQuyenTheoBoPhan() As List(Of CQuyenTheoBoPhanDTO)
        Using cn As SqlConnection = CDataProvider.Connect()
            Dim cm As SqlCommand = New SqlCommand("uspLoadQuyenTheoBoPhan", cn)
            cm.CommandType = CommandType.StoredProcedure
            Dim lquyentheobophan As New List(Of CQuyenTheoBoPhanDTO)
            Using reader As IDataReader = cm.ExecuteReader(CommandBehavior.CloseConnection)
                While reader.Read()
                    lquyentheobophan.Add(New CQuyenTheoBoPhanDTO(reader))
                End While
            End Using
            Return lquyentheobophan
        End Using
    End Function

    Public Function LayQuyenTheoBoPhan(ByVal mabophan As Integer) As CQuyenTheoBoPhanDTO
        Using cn As SqlConnection = CDataProvider.Connect()
            Dim cm As SqlCommand = New SqlCommand("uspLayQuyenTheoBoPhan", cn)
            Dim para As SqlParameter = New SqlParameter("@mabophan", mabophan)
            cm.Parameters.Add(para)
            cm.CommandType = CommandType.StoredProcedure
            Using reader As IDataReader = cm.ExecuteReader(CommandBehavior.CloseConnection)
                If reader.Read() Then
                    Return New CQuyenTheoBoPhanDTO(reader)
                Else
                    Return Nothing
                End If
            End Using
        End Using
    End Function

    Public Function UpdateQuyenTheoBoPhan(ByVal quyenbophan As CQuyenTheoBoPhanDTO) As Integer
        Using cn As SqlConnection = CDataProvider.Connect()
            Dim cm As SqlCommand = New SqlCommand("uspUpdateQuyenTheoBoPhan", cn)
            cm.CommandType = CommandType.StoredProcedure
            Dim para As SqlParameter = New SqlParameter("@ma", quyenbophan.Ma)
            cm.Parameters.Add(para)
            para = New SqlParameter("@muontrasach", quyenbophan.RibbonBarMuonTraSach)
            cm.Parameters.Add(para)

            para = New SqlParameter("@quanlysach", quyenbophan.RibbonBarQuanLySach)
            cm.Parameters.Add(para)
            para = New SqlParameter("@thutienphat", quyenbophan.RibbonBarThuTienPhat)
            cm.Parameters.Add(para)
            para = New SqlParameter("@thethuvien", quyenbophan.RibbonBarTheThuVien)
            cm.Parameters.Add(para)
            para = New SqlParameter("@timkiemtheodocgia", quyenbophan.RibbonBarTimKiemTheoDocGia)
            cm.Parameters.Add(para)
            para = New SqlParameter("@timkiemtheosach", quyenbophan.RibbonBarTimKiemTheoSach)
            cm.Parameters.Add(para)
            para = New SqlParameter("@baocaodocgianotienphat", quyenbophan.RibbonButtonBaoCaoDocGiaNoTienPhat)
            cm.Parameters.Add(para)
            para = New SqlParameter("@baocaomuontheotheloai", quyenbophan.RibbonButtonBaoCaoMuonTheoTheLoai)
            cm.Parameters.Add(para)
            para = New SqlParameter("@baocaosachtratre", quyenbophan.RibbonButtonBaoCaoSachTraTre)
            cm.Parameters.Add(para)
            cm.ExecuteNonQuery()
            Return 1
        End Using
    End Function


End Class
